/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Operations.Bit;

import Operations.CommonFunc;
import Operations.Operation;
import java.awt.image.BufferedImage;

/**
 *
 * @author littlechild
 */
public class OpThreshold implements Operation{

    public BufferedImage operate(BufferedImage image, double[] paras) {
       double threshold=paras[0];
       BufferedImage returnImage=new BufferedImage(image.getWidth(),image.getHeight(),BufferedImage.TYPE_BYTE_BINARY);
       int white=0xffffff;
       int black=0;
       for(int i=0;i!=image.getWidth();++i) {
           for(int j=0;j!=image.getHeight();++j) {
               int rgb=image.getRGB(i, j);
               if(CommonFunc.getGray(rgb)>threshold)
                    returnImage.setRGB(i, j, white);
               else
                   returnImage.setRGB(i, j, black);
           }
       }
       return returnImage;
    }

}
